<?php

namespace App\B2BProject\Custom\Business;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class LicensedGood extends Model
{
    protected $fillable = ['province_id', 'city_id', 'county_id'];

    /**
     * 获取当前授权信息的价格策略
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function priceStrategy()
    {
        return $this->belongsTo('App\B2BProject\Custom\Business\PriceStrategy', 'strategy_id', 'id');
    }

    /**
     * 获取对应的商品信息
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function goods()
    {
        return $this->belongsTo('App\B2BProject\Custom\Business\Goods', 'goods_id', 'id');
    }

    /**
     * 对应的授权请求
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function authorizationRequest()
    {
        return $this->belongsTo('App\B2BProject\Custom\AuthorizationRequest', 'authorization_id', 'id');
    }

    /**
     * @param Builder $builder
     *
     * @return $this
     */
    public function scopeAvailable(Builder $builder)
    {
        return $builder->where('status', true);
    }
}
